$(document).ready(
	function(){
		if (!Attacklab || !Attacklab.wmd) {
			return;
		}

		// build the dom elements
		var form = $("form");

		var textarea = form.find("textarea")[0];
		var previewDiv = form.find("div.preview")[0];

		/***** build the preview manager *****/
		var panes = {input:textarea, preview:previewDiv, output:null};
		var previewManager = new Attacklab.wmd.previewManager(panes);

		/***** build the editor and tell it to refresh the preview after commands *****/
		var editor = new Attacklab.wmd.editor(textarea,previewManager.refresh);
		
		var title = form.find('#title');
		var titlepreview = form.find('h1.preview');
		
		title.keyup(
			function(){
				titlepreview.html($(this).val());
			}
		);
		
		titlepreview.html(title.val());
	}
);